package com.ossjk.qlh.tgb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ossjk.qlh.tgb.entity.OrderDetails;
import com.ossjk.qlh.tgb.mapper.OrderDetailsMapper;
import com.ossjk.qlh.tgb.service.IOrderDetailsService;
import com.ossjk.qlh.tgb.vo.OrderDetailVo;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright  Fri Jan 21 20:50:21 CST 2022 QLH. Tech Ltd. All rights reserved.
 * 
 * @Package: com.ossjk.qlh.projects
 * @ClassName: OrderDetailsController
 * @Description: OrderDetails-服务实现类
 * @author: chair
 * @date:  2022-01-21 20:50:22 
 */
@Service
public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, OrderDetails> implements IOrderDetailsService {


    @Override
    public Map<String,Object> getDetailList(String id) {
        Map<String,Object> map = new HashMap<>();

        List<OrderDetailVo> list = this.baseMapper.selectListByOrderId(id);
        BigDecimal total = new BigDecimal(0);
        for (OrderDetailVo orderDetailVo : list) {
            BigDecimal totalPrice = orderDetailVo.getPrice().multiply(new BigDecimal(orderDetailVo.getCount()));
            orderDetailVo.setTotalPrice(totalPrice);
            total = total.add(totalPrice);
        }
        map.put("total",total);
        map.put("orderDetailList",list);
        return map;
    }

    @Override
    public void removeListByOrderIds(String[] ids) {
        for (String orderId : ids) {
            QueryWrapper<OrderDetails> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("order_id",orderId);
            baseMapper.delete(queryWrapper);
        }
    }
}
